<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>annotate (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">dom.annotate</span>
</div>

<hr/>


  <h2>Classes</h2>
   
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.dom.annotate.annotateTerms"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">annotateTerms<span class="args">(<span class="arg">node</span>,&nbsp;<span class="arg">terms</span>,&nbsp;<span class="arg">annotateFn</span>,&nbsp;<span class="arg">opt_ignoreCase</span>,&nbsp;<span class="arg">opt_classesToSkip</span>,&nbsp;<span class="arg">opt_maxMs</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
      </div>


     <div class="entryOverview">
       Calls <code>annotateFn</code> for each occurrence of a search term in text nodes
under <code>node</code>. Returns the number of hits.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">node</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/DOM/Node">Node</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">A DOM node.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">terms</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">An array of [searchTerm, matchWholeWordOnly] tuples. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">annotateFn</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">A function that takes (1) the number of the term that is "hit", (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">opt_ignoreCase</span>
        : <div class="fullType"><span class="type">*</span></div>
        <div class="entryOverview">Whether to ignore the case of the query terms when looking for matches.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">opt_classesToSkip</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>&gt;<span>&nbsp;|&nbsp;</span><span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type">undefined</span>)</div>
        <div class="entryOverview">Nodes with one of these CSS class names (and its descendants) will be skipped.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">opt_maxMs</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span><span>&nbsp;|&nbsp;</span><span class="type">undefined</span>)</div>
        <div class="entryOverview">Number of milliseconds after which this function, if still annotating, should stop and return.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>&nbsp;
            Whether any terms were annotated.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line51">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.dom.annotate.annotateTermsInNode_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">annotateTermsInNode_<span class="args">(<span class="arg">node</span>,&nbsp;<span class="arg">terms</span>,&nbsp;<span class="arg">annotateFn</span>,&nbsp;<span class="arg">ignoreCase</span>,&nbsp;<span class="arg">classesToSkip</span>,&nbsp;<span class="arg">stopTime</span>,&nbsp;<span class="arg">recursionLevel</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
      </div>


     <div class="entryOverview">
       Recursive helper function.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">node</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/DOM/Node">Node</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">A DOM node.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">terms</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">An array of [searchTerm, matchWholeWordOnly] tuples. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">annotateFn</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">function(number, string) : string  A function that takes : (1) the number of the term that is "hit", (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">ignoreCase</span>
        : <div class="fullType"><span class="type">*</span></div>
        <div class="entryOverview">Whether to ignore the case of the query terms when looking for matches.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">classesToSkip</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>&gt;<span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">Nodes with one of these CSS class names will be skipped (as will their descendants).</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">stopTime</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span></div>
        <div class="entryOverview">Deadline for annotation operation (ignored if 0).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">recursionLevel</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span></div>
        <div class="entryOverview">How deep this recursive call is; pass the value 0 in the initial call.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>&nbsp;
            Whether any terms were annotated.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line106">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.dom.annotate.annotateText"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">annotateText<span class="args">(<span class="arg">text</span>,&nbsp;<span class="arg">terms</span>,&nbsp;<span class="arg">annotateFn</span>,&nbsp;<span class="arg">opt_ignoreCase</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>)</div>
      </div>


     <div class="entryOverview">
       Annotates occurrences of query terms in plain text. This process consists of
identifying all occurrences of all query terms, calling a provided function
to get the appropriate replacement HTML for each occurrence, and
HTML-escaping all the text.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">text</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The plain text to be searched.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">terms</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">An array of [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">annotateFn</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">{function(number, string) : string} A function that takes (1) the number of the term that is &amp;quot;hit&amp;quot;, (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">opt_ignoreCase</span>
        : <div class="fullType"><span class="type">*</span></div>
        <div class="entryOverview">Whether to ignore the case of the query terms when looking for matches.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>)</div>&nbsp;
            The HTML equivalent of <code>text</code> with terms annotated, or null if the text did not contain any of the terms.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line203">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.dom.annotate.helpAnnotateText_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">helpAnnotateText_<span class="args">(<span class="arg">text</span>,&nbsp;<span class="arg">terms</span>,&nbsp;<span class="arg">annotateFn</span>,&nbsp;<span class="arg">ignoreCase</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>)</div>
      </div>


     <div class="entryOverview">
       Annotates occurrences of query terms in plain text. This process consists of
identifying all occurrences of all query terms, calling a provided function
to get the appropriate replacement HTML for each occurrence, and
HTML-escaping all the text.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">text</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The plain text to be searched.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">terms</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">An array of [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. If <code>ignoreCase</code> is true, each search term must already be lowercase. The matchWholeWordOnly value is a per-term attribute because some terms may be CJK, while others are not. (For correctness, matchWholeWordOnly should always be false for CJK terms.).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">annotateFn</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">{function(number, string) : string} A function that takes (1) the number of the term that is &amp;quot;hit&amp;quot;, (2) the HTML string (search term) to be annotated, and returns the annotated term as an HTML string.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">ignoreCase</span>
        : <div class="fullType"><span class="type">*</span></div>
        <div class="entryOverview">Whether to ignore the case of the query terms when looking for matches.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>)</div>&nbsp;
            The HTML equivalent of <code>text</code> with terms annotated, or null if the text did not contain any of the terms.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line237">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.dom.annotate.lowercaseTerms_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">lowercaseTerms_<span class="args">(<span class="arg">terms</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
      </div>


     <div class="entryOverview">
       Converts terms to lowercase.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">terms</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">An array of [{string} searchTerm, {boolean} matchWholeWordOnly] tuples.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>&nbsp;
            An array of [{string} searchTerm, {boolean} matchWholeWordOnly] tuples.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line348">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.dom.annotate.MAX_RECURSION_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">MAX_RECURSION_</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span></div>
     </div>


     <div class="entryOverview">
       The maximum recursion depth allowed. Any DOM nodes deeper than this are
ignored.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line72">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.dom.annotate.NODES_TO_SKIP_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">NODES_TO_SKIP_</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
     </div>


     <div class="entryOverview">
       The node types whose descendants should not be affected by annotation.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line80">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.dom.annotate.NONWORD_RE_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.dom.annotate.</span><span class="entryName">NONWORD_RE_</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp">RegExp</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
     </div>


     <div class="entryOverview">
       Regular expression that matches non-word characters.

Performance note: Testing a one-character string using this regex is as fast
as the equivalent string test ("a-zA-Z0-9_".indexOf(c) &lt; 0), give or take a
few percent. (The regex is about 5% faster in IE 6 and about 4% slower in
Firefox 1.5.) If performance becomes critical, it may be better to convert
the character to a numerical char code and check whether it falls in the
word character ranges. A quick test suggests that could be 33% faster.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_dom_annotate.js.source.html#line178">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>
      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Package dom</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">Package Reference</h2>
            <div id="sideTypeIndex" rootPath="" current="dom.annotate"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
